package top.yvyan.guettable.Gson;

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

import top.yvyan.guettable.bean.PlannedCourseBean;

public class ProgramModel {
    public List<Module> moduleList;

    public List<Module.Course> outerCourseList;

    public static class Module {
        public List<Course> courseList;

        public List<Module> children;

        public static class Course {
            public String code;
            public Double credits;
            public String courseProperty;
            public Double score;
            public String rank;
            public Boolean creditsCourse;
            @SerializedName("nameZh")
            public String courseName;


            public List<String> classTypeList;
        }


        @SerializedName("nameZh")
        public String classType; //课程性质

        public Integer moduleId;
        public Integer typeId;

        public String typeCode;
    }

    // 递归解析Module
    public List<Module.Course> parseModel(List<Module> modules, List<String> ParentClassTypeList) {
        List<Module.Course> courses = new ArrayList<>();
        for (Module module : modules) {
            List<String> classTypeList = new ArrayList<>(ParentClassTypeList);
            classTypeList.add(module.classType);
            for (Module.Course course : module.courseList) {
                course.classTypeList = new ArrayList<>(classTypeList);
            }
            courses.addAll(parseModel(module.children, classTypeList));
        }
        return courses;
    }

    public List<Module.Course> getAllCourse() {
        List<Module.Course> courseList = parseModel(moduleList, new ArrayList<>());
        for (Module.Course course : outerCourseList) {
            course.classTypeList = new ArrayList<>(List.of("计划外课程"));
            courseList.add(course);
        }
        return courseList;
    }
}
